#include <iostream>
#include <thread>
#include <chrono>
#include <ctime>
#include <windows.h>
using namespace std;
void MSleep(int ms)
{
    auto beg = clock();
    for (int i = 0; i < ms; ++i)
    {
        Sleep(1);
        if ((clock() - beg) / (CLOCKS_PER_SEC / 1000) > ms)
            break;
    }
}
int main(int argc, char *argv[])
{
    // 测试c++11的sleep 函数
    int fps = 0;
    auto beg = clock();
    for (;;)
    {
        ++fps;
        auto tem = clock();
        this_thread::sleep_for(10ms);
        if ((clock() - beg) / (CLOCKS_PER_SEC / 1000) > 1000)
        { // 1秒
            cout << "fps = " << fps << endl;
            break;
        }
    }
    // 测试wait事件
    auto handle = CreateEvent(NULL, FALSE, FALSE, NULL);
    fps = 0;
    beg = clock();
    for (;;)
    {
        ++fps;
        WaitForSingleObject(handle, 10);
        if ((clock() - beg) / (CLOCKS_PER_SEC / 1000) > 1000)
        { // 1秒
            cout << "wait fps = " << fps << endl;
            break;
        }
    }
    fps = 0;
    beg = clock();
    for (;;)
    {
        ++fps;
        MSleep(10);
        if ((clock() - beg) / (CLOCKS_PER_SEC / 1000) > 1000)
        { // 1秒
            cout << "MSleep fps = " << fps << endl;
            break;
        }
    }
    return 0;
}